package com.yn.xr.front.user.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.yn.xr.front.base.constants.SystemConstants;

public class SecurityInterceptor extends AbstractInterceptor {
	
	private static final long serialVersionUID = -2901651383814070002L;

	private static final Logger log = LoggerFactory.getLogger(CheckLoginInterceptor.class);
	
	/**
	 * 判断传进来的userId和session中的userId是否一致，不一致则跳转到登陆页面
	 * @param actionInvocation
	 * @return String
	 * @throws Exception
	 */
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String userIdStr = request.getParameter("userId");
		Long userId = (Long) ServletActionContext.getRequest().getSession() .getAttribute(SystemConstants.USERID_SESSION_INFO);

		/*if (userId != null && StringUtils.isNotEmpty(userIdStr) && !userIdStr.equals(userId.toString())) {
			return "login";
		} else {
			return actionInvocation.invoke();
		}*/

		log.info("【SecurityInterceptor.intercept】userId_userIdStr"+userId+"_"+userIdStr);
		return actionInvocation.invoke();
	}

}
